<?php

namespace App\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;

class LogFilter implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = NULL)
    {
        $uri    = $request->getUri();
        $params = urldecode($uri->getQuery());
        $token  = $request->header('token');
        $token  = $token ? $token->getValue() : '';

        if (strtolower($request->getMethod()) == "post") {
            $params = json_encode($_POST, JSON_UNESCAPED_UNICODE);
        }

        log_message('info', "token: {$token}, path: {$uri->getPath()}, method: {$request->getMethod()}, params: {$params}");
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = NULL)
    {
        // TODO: Implement after() method.
    }
}